package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CoffeeBean;
import com.ruoyi.system.service.ICoffeeBeanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 咖啡豆信息Controller
 *
 * @author Lin
 * @date 2024-02-10
 */
@RestController
@RequestMapping("/system/coffee_bean")
public class CoffeeBeanController extends BaseController
{
    @Autowired
    private ICoffeeBeanService coffeeBeanService;

    /**
     * 查询咖啡豆信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:coffee_bean:list')")
    @GetMapping("/list")
    public TableDataInfo list(CoffeeBean coffeeBean)
    {
        startPage();
        List<CoffeeBean> list = coffeeBeanService.selectCoffeeBeanList(coffeeBean);
        return getDataTable(list);
    }

    /**
     * 导出咖啡豆信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:coffee_bean:export')")
    @Log(title = "咖啡豆信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CoffeeBean coffeeBean)
    {
        List<CoffeeBean> list = coffeeBeanService.selectCoffeeBeanList(coffeeBean);
        ExcelUtil<CoffeeBean> util = new ExcelUtil<CoffeeBean>(CoffeeBean.class);
        util.exportExcel(response, list, "咖啡豆信息数据");
    }

    /**
     * 获取咖啡豆信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:coffee_bean:query')")
    @GetMapping(value = "/{coffeeId}")
    public AjaxResult getInfo(@PathVariable("coffeeId") Long coffeeId)
    {
        return success(coffeeBeanService.selectCoffeeBeanByCoffeeId(coffeeId));
    }

    /**
     * 新增咖啡豆信息
     */
    @PreAuthorize("@ss.hasPermi('system:coffee_bean:add')")
    @Log(title = "咖啡豆信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CoffeeBean coffeeBean)
    {
        return toAjax(coffeeBeanService.insertCoffeeBean(coffeeBean));
    }

    /**
     * 修改咖啡豆信息
     */
    @PreAuthorize("@ss.hasPermi('system:coffee_bean:edit')")
    @Log(title = "咖啡豆信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CoffeeBean coffeeBean)
    {
        return toAjax(coffeeBeanService.updateCoffeeBean(coffeeBean));
    }

    /**
     * 删除咖啡豆信息
     */
    @PreAuthorize("@ss.hasPermi('system:coffee_bean:remove')")
    @Log(title = "咖啡豆信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{coffeeIds}")
    public AjaxResult remove(@PathVariable Long[] coffeeIds)
    {
        return toAjax(coffeeBeanService.deleteCoffeeBeanByCoffeeIds(coffeeIds));
    }
}
